package indexer;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.util.Properties;

public class Common {
	public static String SeedListFilename = "";
	public static int RequestTimeout;
	public static int ThreadsCount = 3;
	public static int RecursionLimit;
	public static String WorkingPath;

	private Common() {
		Properties p = new Properties();
		try {
			p.load(new FileReader("Settings.properties"));

			Common.ThreadsCount = Integer.parseInt(p
					.getProperty("ThreadsCount"));
			Common.RequestTimeout = Integer.parseInt(p
					.getProperty("RequestTimeout"));
			Common.RecursionLimit = Integer.parseInt(p
					.getProperty("RecursionLimit"));
			Common.WorkingPath = p.getProperty("RecursionLimit");
			Common.SeedListFilename = p.getProperty("SeedListFilename");

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static char[] Separators = new char[] { ' ', '|', '&', '^', '@',
			'!', '?', '`', '~', '_', '/', '\"', ',', '\'', ';', ':', '.', '(',
			')', '[', ']', '<', '>', '%', '*', '$', '+', '-', '=', '#', '*'};

	// / <summary>
	// / Regex pattern that matches sequence of www a digit(may not occur) and a
	// dot
	// / </summary>
	public static String MatchWwwDigitDotPattern = "^www\\d{0,1}\\.";

	// / <summary>
	// / Regex pattern that matches sequence of empty spaces
	// / </summary>
	public static String MatchEmptySpacesPattern = "\\s+";

	public static String ErrorLogsFolder = "\\ErrorLogs";
	public static String MessageLogsFolder = "\\MessageLogs";

	public static String ErrorLog = ErrorLogsFolder + "\\ErrorLog.txt";
	public static String ErrorWebLog = ErrorLogsFolder + "\\ErrorWebLog.txt";
	public static String ErrorWebTimeoutLog = ErrorLogsFolder
			+ "\\ErrorWebTimeoutLog.txt";
	public static String ErrorWebProtocolLog = ErrorLogsFolder
			+ "\\ErrorWebProtocolLog.txt";

	public static String MessagesLog = MessageLogsFolder + "\\MessagesLog.txt";
	public static String IndexedLinksLog = MessageLogsFolder
			+ "\\IndexedLinksLog.txt";

	public static String DateFormat = "dd/MM/yyyy HH:mm";
	public static String HTTP = "http://";

	public static String GetHttpAuthority(URI uri) {
		return HTTP + GetAuthority(uri);
	}

	public static String GetAuthority(URI uri) {
		return uri.getAuthority().replaceFirst(Common.MatchWwwDigitDotPattern,
				"");
	}

}
